<template>
<div class="uni-flex uni-column" >
    <div class="flex-item flex-item-V text-xl" style="text-align: center;height: 33%;padding-top: 10%">
<!--        <navigator url="/pages/home/StoreList" open-type="redirect">{{this.storeMain.name}}></navigator>-->
        <text class="text-white" @click="onClickStoreMain">{{this.storeMain.name}}></text>
    </div>
    <div class="flex-item flex-item-V padding" >
        <div class="text-df" style="text-align: center;">
            <text style="color: #d0e7e3;">今日总收入</text>
        </div>
        <div class="text-sl" style="text-align: center;">
            <text class="text-price text-white">{{this.todayBusinessIncome.salesVolume}}</text>
        </div>
    </div>
    <div class="flex-item flex-item-V" >
      <div class="flex justify-around" style="width: 100%">
        <div class="margin-xs radius" style="width: 50%;padding-left: 10%">
          <div class="text-df" style="text-align: center;"><text style="color: #d0e7e3;">收款笔数</text></div>
          <div class="text-xxl padding-sm" style="text-align: center;"><text class="text-white">{{ this.todayBusinessIncome.transactionsNum }}</text></div>
        </div>
        <div class="margin-xs radius" style="width: 50%;padding-right: 10%">
          <div class="text-df" style="text-align: center;"><text style="color: #d0e7e3;">毛利</text></div>
          <div class="text-xxl padding-sm" style="text-align: center;"><text class="text-price text-white">{{ this.todayBusinessIncome.gross }}</text></div>
        </div>
      </div>
    </div>
</div>
</template>

<script>
import request from "../../../utils/request";
const app = getApp()
export default {
    name: "head",

    data() {
        return {
            storeMain:uni.getStorageSync("currentStoreMain"),
            userMain:uni.getStorageSync("userMain"),
            todayBusinessIncome:app.globalData.todayBusinessIncome
        }
    },
    methods:{
        onClickStoreMain:function () {
            uni.navigateTo({
                url:"/pages/home/StoreList"
            })
        }
    },
  mounted() {
        request.get("/store/get/storeList/"+this.userMain.id).then(res=>{
            uni.setStorageSync("storeMainList",res.data)
            if (this.storeMain===null||this.storeMain===""){
                uni.setStorageSync("currentStoreMain",uni.getStorageSync("storeMainList").at(0))
                this.storeMain=uni.getStorageSync("currentStoreMain")
            }
          const now = new Date();
          let year = now.getFullYear(); //得到年份
          let month = now.getMonth() + 1;//得到月份
          let date = now.getDate();//得到日期
          if (month<10)
            month="0"+month
          if (date<10)
            date="0"+date
          app.globalData.nowDate = year+"-"+ month+"-"+date+"T00:00:00";

          let tomorrow=now.setDate(now.getDate()+1)
          tomorrow=new Date(tomorrow)
          year = tomorrow.getFullYear();
          month = tomorrow.getMonth() + 1;
          date = tomorrow.getDate();
          if (month<10)
            month="0"+month
          if (date<10)
            date="0"+date
          const tomorrowDate=year+"-"+ month+"-"+date+"T00:00:00"

          app.globalData.businessDate={
            startDate:app.globalData.nowDate,
            endDate:tomorrowDate,
            storeId:this.storeMain.storeId
          }
          request.post("/business/get/businessIncomeByHour",app.globalData.businessDate).then(res=>{
            console.log(res)
            this.todayBusinessIncome=res.data
          })

          console.log(app.globalData.businessDate)
        })



      uni.$once('isRefreshOnHead',(data)=>{
        request.get("/store/get/storeList/"+this.userMain.id).then(res=>{
          uni.setStorageSync("storeMainList",res.data)
          if (this.storeMain===null||this.storeMain===""){
            uni.setStorageSync("currentStoreMain",uni.getStorageSync("storeMainList").at(0))
            this.storeMain=uni.getStorageSync("currentStoreMain")
          }
        })

        const now = new Date();
        let year = now.getFullYear(); //得到年份
        let month = now.getMonth() + 1;//得到月份
        let date = now.getDate();//得到日期
        if (month<10)
          month="0"+month
        if (date<10)
          date="0"+date
        app.globalData.nowDate = year+"-"+ month+"-"+date+"T00:00:00";

        let tomorrow=now.setDate(now.getDate()+1)
        tomorrow=new Date(tomorrow)
        year = tomorrow.getFullYear();
        month = tomorrow.getMonth() + 1;
        date = tomorrow.getDate();
        if (month<10)
          month="0"+month
        if (date<10)
          date="0"+date
        const tomorrowDate=year+"-"+ month+"-"+date+"T00:00:00"

        app.globalData.businessDate={
          startDate:app.globalData.nowDate,
          endDate:tomorrowDate,
          storeId:this.storeMain.storeId
        }
        request.post("/business/get/businessIncomeByHour",app.globalData.businessDate).then(res=>{
          console.log(res)
          this.todayBusinessIncome=res.data
        })


        console.log(app.globalData.businessDate)
      })
    },

}
</script>

<style scoped>

</style>